package com.tan.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tan.entity.PageResult;
import com.tan.entity.Result;
import com.tan.mapper.ImagesMapper;
import com.tan.pojo.Brand;
import com.tan.pojo.Images;
import com.tan.service.IImagesService;
import com.tan.vo.BrandQueryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author tanMax
 * @since 2022-09-30
 */
@RestController
@RequestMapping("/images")
public class ImagesController extends BaseController{
    @Autowired
    private IImagesService imagesService;

    @PostMapping("/search/{currentPage}/{pageSize}")
    public Result search(@PathVariable Integer currentPage, @PathVariable Integer pageSize){
        Page<Images> imagesPage = new Page<>(currentPage,pageSize);
        Page<Images> page = imagesService.page(imagesPage);
        PageResult pageResult = new PageResult(page.getTotal(),page.getRecords());
        return toDataResult(pageResult);
    }
    @PostMapping("/add")
    public Result add(@RequestBody Images images){
        boolean save = imagesService.save(images);
        return toResult(save);
    }
    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable String id){
        boolean b = imagesService.removeById(id);
        return toResult(b);
    }
    @PutMapping
    public Result updateById(@RequestBody Images images){
        boolean b = imagesService.updateById(images);
        return toResult(b);
    }
    @GetMapping("/{id}")
    public Result byId(@PathVariable String id){
        Images images = imagesService.getById(id);
        return toDataResult(images);
    }
}
